package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.dao.AuthorityDao;
import cn.gjculture.shopping.api.dao.CommonDeleteMapper;
import cn.gjculture.shopping.api.dao.CommonUpdateMapper;
import cn.gjculture.shopping.api.entity.Authority;
import cn.gjculture.shopping.api.service.AuthorityService;
import cn.gjculture.shopping.api.util.DateUtil;
import cn.gjculture.shopping.api.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthorityServiceImpl implements AuthorityService {

    @Autowired
    AuthorityDao authorityDao;

    @Autowired
    CommonUpdateMapper commonUpdateMapper;

    @Autowired
    CommonDeleteMapper commonDeleteMapper;

    @Override
    public List<Authority> query() {
        return authorityDao.query();
    }

    @Override
    public int insert(Authority authority) {
        authority.setAuthorityId(UUIDUtil.getUUID());
        authority.setInsertTime(DateUtil.getTimestamp());
        authority.setUpdateTime(DateUtil.getTimestamp());
        return authorityDao.insert(authority);
    }

    @Override
    public int update(Authority authority) {
        authority.setUpdateTime(DateUtil.getTimestamp());
        return commonUpdateMapper.updateAuthority(authority);
    }

    @Override
    public Authority queryById(String authorityId) {
        return authorityDao.queryById(authorityId);
    }

    @Override
    public int delete(List<String> authorityIds) {
        return commonDeleteMapper.deleteAuthority(authorityIds);
    }
}
